import { createApp } from "vue";
import { createPinia } from "pinia"; //vue3全局状态管理工具
import App from "./App.vue";
import router from "./router";
import axios from "axios";
import { useUserStore } from "./stores/user"; //在应用初始化时调用 initializeFromLocalStorage

import "./assets/css/reset.css";
import "./assets/css/global.css";
import "./assets/css/font.css";

// Vuetify
import "vuetify/styles";
import { createVuetify } from "vuetify";
import * as components from "vuetify/components";
import * as directives from "vuetify/directives";

const vuetify = createVuetify({
  components,
  directives,
});

// 设置 Axios 的默认头部（使用 localStorage 中的令牌）
const setAuthHeader = () => {
  const token = localStorage.getItem("access_token");
  if (token) {
    axios.defaults.headers.common["Authorization"] = `bearer ${token}`;
  }
};
// 调用设置头部的函数
setAuthHeader();

const app = createApp(App);
const pinia = createPinia();
//实现组件的全局注册
// app.component("Header",Header)
//实现全局数据
// app.provide("gloabData","全局数据")
//实现路由
app.use(router);
app.use(vuetify);
app.use(pinia);

const userStore = useUserStore();
userStore.initializeFromLocalStorage();

app.mount("#app");
